﻿using Hezi.BLL;
using Hezi.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Newtonsoft.Json;

namespace Hezi.MsgService
{
    [ServiceContract(Namespace = "hezi.xxxfeng.com")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    //[JavascriptCallbackBehavior(UrlParameterName = "jsoncallback")]
    public class Send
    {
        // 要使用 HTTP GET，请添加 [WebGet] 特性。(默认 ResponseFormat 为 WebMessageFormat.Json)
        // 要创建返回 XML 的操作，
        //     请添加 [WebGet(ResponseFormat=WebMessageFormat.Xml)]，
        //     并在操作正文中包括以下行:
        //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
        [OperationContract]
        [WebGet]
        public SendMsgModel Msg(string name,string tl,string msg)
        {
            CacheManager cm = new CacheManager();
            if (!cm.HashHasValue(name))
            {
                return new SendMsgModel() { ret = 2, msg = "用户名不存在" };
            }
            MsgModel msgModel = new MsgModel() { Title = tl, Message = msg,CreatTime=DateTime.Now };
            
            //bool flag= cm.StringSet(name, JsonConvert.SerializeObject(msgModel), 10000);
            // 在此处添加操作实现
            //if (flag)
            //{
             //   return new SendMsgModel() { ret = 0, msg = "发送成功" };
            //}else
            //{
            //    return new SendMsgModel() { ret = 1, msg = "发送失败" };
            //}
            long r= cm.ListSet(ConfigKey.msgKeyStart+name, msgModel);
            if (r > 0)
            {
                return SendMsgModel.Success();
            }else
            {
                return new SendMsgModel() { ret = 1, msg = "发送失败" };
            }
            
        }

        // 在此处添加更多操作并使用 [OperationContract] 标记它们
    }
}
